#ifndef TRANSPARENT_MODE_H
#define TRANSPARENT_MODE_H

#include "serial_port/serial_port.h"
#include <iostream>
#include <cstring>
#include <thread>
#include <queue>
#include <mutex>
#include <condition_variable>
#include <unordered_map>
#include <functional>
#include <chrono>
#include <deque>
#include <atomic>

class transparent_mode
{

public:
    transparent_mode(const std::string& serial_port);
    ~transparent_mode();

    void start();    // 启动透传模式
    void stop();    // 停止透传模式

    void send_bytes_data(unsigned char *p_data, int len);
    int read_bytes_poll(unsigned char *p_data, int len);

private:
    void sending_thread();    //数据发送线程
    void receiving_thread();    //数据接收线程
    void processing_thread();    //数据处理线程

    // 线程控制
    std::atomic<bool> running;
    std::thread send_thread, recv_thread, process_thread;

    serial_port serial;    // 串口对象

    std::deque<std::vector<unsigned char>> send_queue;     //发送队列
    std::deque<std::vector<unsigned char>> recv_queue;    //接收队列

    std::mutex send_mtx, recv_mtx;    //发送和接收互斥锁
    std::condition_variable send_cv, recv_cv;    //发送和接收的条件变量

    // 发送和接收数据的超时设置
    unsigned int timeout_ms = 1000;
    unsigned int max_retries = 3;
};






#endif

